﻿using System;
using System.Windows.Forms;
using Mini.Common;
using Mini.Resource;

namespace Mini.DownloadTool
{
    public class EventStatic : BaseHelper
    {
        private readonly DirectoryHelper _directoryHelper;
        
        public EventStatic()
        {
            _directoryHelper = new DirectoryHelper();
        }

        #region button event
        public void btnAbout_Click(object sender, EventArgs e)
        {
            var aboutForm = new frmAboutMe();
            aboutForm.Show();
        }

        public void btnOption_Click(object sender, EventArgs e)
        {
            var optionForm = new frmOption();
            optionForm.Show();
        }

        public void btnExit_Click(object sender, EventArgs e)
        {
            ShowMessageConfirmExit(false);
        }
        #endregion

        #region form event
        public void MainForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            ShowMessageConfirmExit();
        }
        public void MainForm_Load(object sender, EventArgs e)
        {
            var form = sender as Form;
            if (form != null)
            {
                form.Controls[TextboxNameSaveTo].Text = DirectoryHelper.GetDirectoryDefault();
            }

        }
        #endregion

        #region private method

        public void ShowMessageConfirmExit(bool isButtonCloseForm = true)
        {
            var result = MessageBox.Show(MessageResource.ConfirmExit, MessageResource.TitleMessage, MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            if (result.Equals(DialogResult.OK))
            {
                Application.Exit();
            }
            else if (!result.Equals(DialogResult.OK) && isButtonCloseForm)
            {
                Application.Run();
            }
        }
        #endregion

    }
}
